<template>
  <div class="wapper">
    <el-container style="100%">
      <ContentType></ContentType>
      <el-main style="background:#fff;margin-left:10px">
        <div class="table-wrap" v-show="listShow">
          <div class="handle-box3">
            <el-form :inline="true" ref="form" class="demo-form-inline">
              <div class="uers-left">
                <el-form-item label="搜索：">
                  <el-input v-model="searchForm.name" placeholder="标题"></el-input>
                </el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="searchSubmit()">搜索</el-button>
              </div>
              <div class="uers-right">
                <span class="btn-r">
                  <el-button type="primary" plain icon="el-icon-plus" @click="addSubmit">新增</el-button>
                </span>
              </div>
            </el-form>
          </div>
          <div class="tabbox">
          <el-table
            :data="dataList"
            height="100%"
            border
            class="tabbox"
            ref="multipleTable"
            :header-cell-style="{background:'#f2f6fc',color:'#606266'}"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" width="55" align="center"></el-table-column>
            <el-table-column prop="title" label="标题" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.title}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="indexNo" label="索引" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.indexNo}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="disabled" label="启用/禁用" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.disabled==0?'禁用':'启用'}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="createDate" label="创建时间" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.createDate}}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="180" align="center">
              <template slot-scope="scope">
                <el-button type="text" @click="handleEdit(scope.$index,scope.row)">编辑</el-button>
                <el-button type="text" class="red" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table></div>
          <div class="fb"><el-pagination
            class="pag"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            background
          ></el-pagination></div>
        </div>
        <DeleteDialog
          :delVisible="delVisible"
          @deleteData="deleteData"
          @handleCloseVisible="handleCloseVisible"
        ></DeleteDialog>
        <EditContent :editShow="editShow" :editData="editData" @backFunStu="getFunStu"></EditContent>
      </el-main>
    </el-container>
  </div>
</template>
<script>
import EditContent from "../../../components/major/committee/EditContent";
import ContentType from "../../../components/public/ContentType";
import DeleteDialog from "../../../components/public/DeleteConfim";
import bus from "../../../components/common/bus.js";

export default {
  data() {
    return {
      total: 0, //总条数
      currentPage: 1, //初始页
      pagesize: 10, // 每页的数据
      searchForm: {
        name: ""
      },
      editData: {},
      listShow: true,
      delVisible: false,
      projectContent_Id: "",
      editShow: false,
      dataList: [],
      multipleSelection: [],
      productId: "",
      projectContentTypeId:0
    };
  },
  mounted() {
    // this.tabheight=(this.$refs.getheight.offsetHeight-165)
  },
  created() {
    this.getData();

    var product_id = localStorage.getItem("project_Id");
    this.productId = product_id;

    bus.$on("putrole", val => {
      this.projectContentTypeId = val
      this.getSearch();
    });
  },
  methods: {
    handleSizeChange(val) {
      this.pagesize = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getData();
    },
    handleEdit(index, row) {
      this.editData = row;
      this.listShow = false;
      this.editShow = true;
    },
    // 获取数据
    getData() {
      this.$axios.get("/ProjectContent/").then(res => {
        if (res.data.hasError == false) {
          this.dataList = [...res.data.data];
          this.total = res.data.total;;
        }
      });
    },
    searchSubmit() {
      this.getSearch();
    },
    getSearch(){
      var search = {
        name: this.searchForm.name,
        pageIndex: this.currentPage - 1,
        pageSize: this.pagesize,
        projectContentTypeId: this.projectContentTypeId,
        projectId: this.productId
      };

      this.$axios.post("/PageContentType/Search", search).then(res => {
        if (res.data.hasError == false) {
          this.dataList = [...res.data.data];
          this.total = res.data.total;;
        }
      });
    },
    addSubmit() {
      this.listShow = false;
      this.editShow = true;
    },
    handleDelete(index, row) {
      this.projectContent_Id = row.projectContentId;
      this.delVisible = true;
    },
    deleteData() {
      this.$axios
        .delete(`/ProjectContent/${this.projectContent_Id}`)
        .then(res => {
          if (res.data.hasError == false) {
            this.$message.success("删除成功！");
            this.delVisible = false;
            this.getData();
          }
        });
    },
    handleCloseVisible() {
      this.projectContent_Id = "";
      this.delVisible = false;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    getFunStu() {
      this.listShow = true;
      this.editShow = false;
      this.getData();
    }
  },
  components: {
    EditContent,
    ContentType,
    DeleteDialog
  }
};
</script>
<style lang="scss" scope>
.pag {
  position: absolute;
  bottom: 0;
}

.table-wrap {
  margin-left: 10px;
  height: 100%;
}
.el-main {
  border-radius: 5px;
  position: relative;
}
.uers-left {
  float: left;
}
.uers-right {
  float: right;
}
</style>